package com.example.shopping.mapper;

import com.example.shopping.pojo.Carts;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CartsMapper {

    @Update("""
            update carts set quantity = #{quantity} where cartId = #{cartId};
            """)
    int update(Carts carts);


    @Select("""
            select * from Carts where customerId = #{customerId} and productId = #{productId};
            """)
    Carts findById(Integer customerId, Integer productId);

    /**
     * @Description: 添加商品到购物车
     * @auther: uu
     * @date: 2023/6/29 19:46
     */
    @Insert("""
            insert into  carts values(null,#{customerId},#{productId},#{quantity});
            """)
    int insert(Carts carts);

    /**
     * @Description: 查询购物车所有商品
     * @auther: uu
     * @date: 2023/6/29 19:47
     */
    @Select("""
            select * from carts;
            """)
    List<Carts> selectAll();
}
